package com.digitalchina.lxnsy.activity.old;

import android.content.res.ColorStateList;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;

import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：白彦东
 * 创建时间：2017/1/12 9:55
 * 修改备注：
 * ================================================
 */

public class TradeSuccessActivity extends BaseActivity {

    @Bind(R.id.tv_success_tips)
    TextView tvSuccessTips;
    @Bind(R.id.trade_success_tv_product_name)
    TextView tradeSuccessTvProductName;
    @Bind(R.id.trade_success_tv_return_mall)
    TextView tradeSuccessTvReturnMall;

    private String tips = "";
    private String type = "";

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_trade_success);
        setTitle("支付成功");
    }

    @Override
    public void initMember() {
        if (getIntent().hasExtra("map")) {
            Map<String, Object> map = (Map<String, Object>) getIntent().getSerializableExtra("map");
            type = String.valueOf(map.get("type"));
            tips = StringUtil.jointString("已经成功购买 ", map.get("productName").toString());

            if(type.equals("3")){
                tradeSuccessTvReturnMall.setText("返回生产标准列表");
//                tvSuccessTips.setText("");
            }else if(type.equals("4")){
                tradeSuccessTvReturnMall.setText("返回标准化生产列表");
            }
        }


        setContent(tips);
    }

    private void setContent(String tips) {
        ColorStateList colorStateList = ColorStateList.valueOf(0xff555555);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(tips);
        spannableStringBuilder.setSpan(new TextAppearanceSpan(null, 0, 28, colorStateList, null), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tradeSuccessTvProductName.setText(spannableStringBuilder);
    }

    @Override
    public void addListener() {
        tradeSuccessTvReturnMall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (type) {
                    case "1":
                        GotoUtil.gotoActivity(TradeSuccessActivity.this, MyOrderListActivity.class, true);
                        break;
                    case "2":
                        GotoUtil.gotoActivity(TradeSuccessActivity.this, MyShareBuyOrderListActivity.class, true);
                        break;
                    case "3":
                        GotoUtil.gotoActivity(TradeSuccessActivity.this, SelectProductionActivityV2.class, true);
                        break;
                    case "4":
                        GotoUtil.gotoActivity(TradeSuccessActivity.this, StandardProductionActivity.class, true);
                        break;
                    default:
                        finish();
                        break;
                }

            }
        });
    }

    @Override
    public void setHandler() {

    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
